import Toast from '@vant/weapp/toast/toast';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    voteData:{},
    checkData:[],
    radio: '',
    result: [],
    id:'',
    uid:'',
    isMultiple:'',
    finish:'已完成',
    unfinish:'待完成',
    single:'单选',
    multiple:'多选',
    options:[],
  },
  onChange2(event) {
    this.setData({
      radio: event.detail,
    });
  },
  onChange1(event) {
    console.log(event.detail)
    this.setData({
      result: event.detail,
    });
  },
//已投票的按钮
finishVote(){
  Toast('您已完成投票！')
},
//提交投票
  submitVote(){
    if(isMultiple){
      wx.request({
        url: 'http://8.129.104.110/userVoteOptions', //多选接口地址
        data: {
          userId:uid,    //注意这里是字符串，不知道是否要转换为int类型
          voteId:id,
          integers:result
        },
        method:'POST',
        header: {
          'content-type': 'application/json' // 默认值
        },
        success: function (res) {
          var data=res.data.data;
          console.log(data)
        },
      })
    }
    else{
      wx.request({
        url: 'http://8.129.104.110/userVote', //单选接口地址
        data: {
          userId:uid,
          voteId:id,
          integers:[radio]
        },
        header: {
          'content-type': 'application/json' // 默认值
        },
        method:'POST',
        success: function (res) {
          var data=res.data.data;
          console.log(data)
        },
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this
    var vid=wx.getStorageSync('vid')
    var isM=wx.getStorageSync('isMultiple')
    this.isMultiple=isM
    this.id=vid
    wx.request({
      url: 'http://8.129.104.110/vote/'+vid, //接口地址
      data: {
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        var data=res.data.data;
        console.log(data)
        that.setData({
          voteData: data.voteEntity,
          checkData:data.voteOptionsEntities
        })
      },
    })
    //获取用户已投选择
    // this.getOptions()
  },
  //获取已选项
  getOptions(){
    var that=this
    wx.request({
      url: 'http://8.129.104.110/userVoteOptions/'+this.uid+this.vid, //接口地址
      data: {
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        var data=res.data.data;
        console.log(data)
        that.setData({
          options:data //？？？？
        })
      },
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})